/* */ scene = window.getScene(); sel = scene.getSelection(); trisPresent = false; //one of these objects needs to be a trimesh for(int i = 0; i < sel.length; i++) { if(!(scene.getObject(sel[i]).object instanceof TriangleMesh)) { continue; } else { trisPresent = true; break; } } if( !trisPresent ) { new BStandardDialog("Triangle Mesh Required", "There are no triangle mesh's in your selection", BStandardDialog.ERROR).showMessageDialog(window); return; } // Display a dialog for selecting the smoothing options. cutoffSlider = new ValueSlider(0.0, 180.0, 180, 30.0); methodChoice = new BComboBox(new Object [] { Translate.text("menu.none"), Translate.text("menu.shading"), Translate.text("menu.interpolating"), Translate.text("menu.approximating"), }); dlg = new ComponentsDialog(window, "Select Options for Smoothing Mesh", new Widget [] {cutoffSlider, methodChoice}, new String [] {"Cutoff Angle", "Smoothing Method"}); if (dlg.clickedOk()) { nonMeshFound = false; smoothingMethod = methodChoice.getSelectedIndex(); cutoffValue = cutoffSlider.getValue(); for(i = 0; i < sel.length; i++) { obj = scene.getObject(sel[i]).object; if(obj instanceof TriangleMesh) { meshInfo = scene.getObject(sel[i]); mesh = meshInfo.object; edge = mesh.getEdges(); face = mesh.getFaces(); vert = mesh.getVertices(); cutoff = Math.cos(cutoffValue*Math.PI/180.0); for (int i = 0; i < edge.length; i++) { ed = edge[i]; if (ed.f2 == -1) continue; // This is a boundary edge. f1 = face[ed.f1]; f2 = face[ed.f2]; norm1 = vert[f1.v1].r.minus(vert[f1.v2].r).cross(vert[f1.v1].r.minus(vert[f1.v3].r)); norm2 = vert[f2.v1].r.minus(vert[f2.v2].r).cross(vert[f2.v1].r.minus(vert[f2.v3].r)); norm1.normalize(); norm2.normalize(); if (norm1.dot(norm2) < cutoff) ed.smoothness = 0.0f; else ed.smoothness = 1.0f; } mesh.setSmoothingMethod(smoothingMethod); scene.objectModified(mesh); } else { if( !nonMeshFound ) { new BStandardDialog("Non Triangle Mesh Object found", "One or more of the objects aren't Triangle Mesh's, skipping it/them.", BStandardDialog.ERROR).showMessageDialog(window); nonMeshFound = true; } continue; } } }